package com.dongge.service;

import com.dongge.dao.CURDDaoBase;
import com.dongge.entity.Right;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2015/11/3.
 */
@Service
public class RightService extends CURDDaoBase<Right> {

    /**
     * 获取以parentId为父权限下的子权限
     * @param parentId
     * @return
     */
    public List<Right> findRightsByParentId(Long parentId){
        if(parentId == null){
            String hsql = "from Right r where r.parent.id is null order by r.name";
            return getSession().createQuery(hsql)
                    .list();
        }
        String hsql = "from Right r where r.parent.id = :parentId order by r.name";
        return  getSession().createQuery(hsql)
                            .setLong("parentId",parentId)
                            .list();
    }
}
